import {
    pageQueryActivity,
    logicDeleteActivityById,
    logicBatchDeleteActivityByIds,
    logicDeleteActivityRegById,
    logicBatchDeleteActivityRegByIds,
    pageQueryActivityReg,
    queryActivityType,
    updateActivityReq,
    addActivityReq,
    updateActivityRegReq
} from "@/api/admin/common";

const state = {
    activityRespData: [],
    activityTotal: 0,
    activityRegRespData: [],
    totalReg: 0,

    activityType: [],
    activityTypeTotal: 0,
};
const mutations = {
    // 分页查询活动信息
    pageQueryActivityMutations(state, param) {
        state.activityRespData = param.data;
        state.activityTotal = param.total;
    },
    // 分页查询活动信息
    pageQueryActivityRegMutations(state, param) {
        state.activityRegRespData = param.data;
        state.totalReg = param.total;
    },
    pageQueryActivityTypeListMutations(state, param) {
        state.activityType = param.data;
        state.activityTypeTotal = param.total;
    }
};
const actions = {
    // 分页查询活动信息
    async pageQueryactivityListActions(context, page) {
        await pageQueryActivity(page).then(resp => {
            if (!resp) return;
            console.log('activity-->', resp.data);
            context.commit('pageQueryActivityMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },
    async addActivityActions(context, form) {
        await addActivityReq(form).then(
            (resp) => {
                if (!resp) return;
                console.log(resp);
            },
            (error) => {
                console.log(error);
            }
        );
    },
    async updateActivityActions(context, form) {
        await updateActivityReq(form).then(resp => {
            if (!resp) return;
            console.log(resp);
            // message(messageType().success, '操作成功');

        }, error => {
            console.log(error);

        })
    },
    // 逻辑删除资讯信息
    async logicDeleteActivityByIdActions(context, id) {
        await logicDeleteActivityById(id).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },

    // 批量逻辑删除资讯信息
    async logicBatchDeleteActivityByIdsActions(context, ids) {
        await logicBatchDeleteActivityByIds(ids).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },


    // --- 活动报名信息
    // 分页查询活动报名信息
    async pageQueryactivityRegListActions(context, page) {
        await pageQueryActivityReg(page).then(resp => {
            if (!resp) return;
            console.log('activityReg-->', resp.data);
            context.commit('pageQueryActivityRegMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },
    async updateActivityRegReqActions(context, form) {
        await updateActivityRegReq(form).then(resp => {
            if (!resp) return;
            console.log(resp);
            // message(messageType().success, resp.data.msg);

        }, error => {
            console.log(error);

        })
    },
    // 逻辑删除资讯信息
    async logicDeleteActivityRegByIdActions(context, id) {
        await logicDeleteActivityRegById(id).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },

    // 批量逻辑删除资讯信息
    async logicBatchDeleteActivityRegByIdsActions(context, ids) {
        await logicBatchDeleteActivityRegByIds(ids).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },

    async pageQueryActivityTypeListActions(context,page) {
        await queryActivityType(page).then(resp => {
            if (!resp) return;
            console.log('activityType-->', resp);
            context.commit('pageQueryActivityTypeListMutations', resp.data)
        }, error => {
            console.log(error);

        })
    },


};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
}